package client.comm.baoding.adapter

import android.content.Context
import android.content.Intent
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.recyclerview.widget.RecyclerView
import client.comm.commlib.base.BaseLoadmoreAdapter
import client.comm.commlib.base.BindingViewHoder
import client.comm.baoding.R
import client.comm.baoding.api.bean.LevelIncome
import client.comm.baoding.api.bean.TdBean
import client.comm.baoding.api.bean.UserInfo
import client.comm.baoding.databinding.*
import client.comm.baoding.ui.TdSubActivity
import client.comm.baoding.ui.TdlstjActivity
import client.comm.baoding.ui.TuiGuangActivity
import client.comm.commlib.utils.StoreUtil

import com.bumptech.glide.RequestManager

class SubsidyAdapter : BaseLoadmoreAdapter<LevelIncome.Level> {

    val manager: RequestManager

    constructor(context: Context, manager: RequestManager) : super(context) {
        this.manager = manager
    }

    override fun createVh(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
        return BindingViewHoder(
            DataBindingUtil.inflate(
                layoutInflater,
                R.layout.item_subsidy,
                parent,
                false
            )
        )
    }

//    fun submitData(list: MutableList<String?>) {
//        super.submitList(list)
//    }

    override fun bindVh(holder: RecyclerView.ViewHolder, position: Int) {
        val bindingViewHolder = holder as BindingViewHoder<ViewDataBinding>
        val binding = bindingViewHolder.binding as ItemSubsidyBinding
        binding.event = this
        binding.bean = getItem(position)
        /* this.tdBean1.apply {
             binding.teamNum = team_num
             binding.userBuy = user_buy
             binding.teamBuy = team_buy
             binding.directBuy = direct_buy
         }

         StoreUtil.getBean<UserInfo>(context)?.let {
             binding.username = it.nickname
             binding.phone = it.phone

             if (it.avatar != null) {
                 manager.load(it.avatar).error(R.mipmap.ic_launcher)
                     .into(binding.userAvatar)
             } else {
                 binding.userAvatar.setImageResource(R.mipmap.ic_launcher)
             }
         }*/

    }

    fun onItemClick(b: TdBean.Sub) {
        context.startActivity(Intent(context, TdSubActivity::class.java).apply {
            putExtra("bean", b.id)
        })
    }


    fun tuiguang() {
        context.startActivity(Intent(context, TuiGuangActivity::class.java))
    }

    /**
     * 历史推荐
     */
    open fun lstj() {
//        startActivity(Intent(context, TdActivity::class.java).apply {
//            putExtra("bean", StoreUtil.getBean<UserInfo>(requireContext())!!.id)
//        })

//        context.startActivity(Intent(context, TdlstjActivity::class.java)
//            .apply {
//                putExtra("bean", StoreUtil.getBean<UserInfo>(context)!!.id)
//            }
//        )
    }

}